home *** CD-ROM | disk | FTP | other *** search
/ Language/OS - Multiplatform Resource Library / LANGUAGE OS.iso / tcl / tclm_1_0.lha / tclm-1.0 / m1to0 < prev    next >
Text File  |  1993-08-16  |  1KB  |  56 lines

  1. #!/usr/local/bin/tclm -f
  2. if {[string compare [lindex $argv 0] -f] == 0} {
  3.     set argc [expr {$argc - 2}]
  4.     set argv [lrange $argv 2 end]
  5. }
  6.  
  7. if {$argc > 2} {
  8.     puts stderr "usage: m1to0 [infile [outfile]]"
  9.     exit 1
  10. }
  11. set in_file stdin
  12. set out_file stdout
  13. if {$argc > 0} {
  14.     set in_file_name [lindex $argv 0]
  15.     if {[catch {open $in_file_name "r"} in_file]} {
  16.         puts stderr "Couldn't open $in_file_name: $in_file"
  17.         exit 1
  18.     }
  19.     if {$argc > 1} {
  20.         set out_file_name [lindex $argv 1]
  21.         if {[catch {open $out_file_name "w"} out_file]} {
  22.             puts stderr "Couldn't open $out_file_name: $out_file"
  23.             exit 1
  24.         }
  25.     }
  26. }
  27.  
  28. if {[catch {midiread $in_file} in_mfile]} {
  29.     puts stderr "Couldn't read MIDI file: $in_mfile"
  30.     exit 1
  31. }
  32.  
  33. set num_tracks [midiconfig $in_mfile tracks]
  34.  
  35. for {set i 0} {$i < $num_tracks} {incr i} {
  36.     lappend track_list "$in_mfile $i 1"
  37. }
  38.  
  39. set out_mfile [midimake]
  40. midiconfig $out_mfile format 0
  41. midiconfig $out_mfile tracks 1
  42. midiconfig $out_mfile division [midiconfig $in_mfile division]
  43.  
  44. set delta [midimerge "$out_mfile 0" $track_list 0]
  45. midiput $out_mfile 0 $delta metaeot
  46.  
  47. if {[catch {midiwrite $out_mfile $out_file} err]} {
  48.     puts stderr "Couldn't write format 0 MIDI file: $err"
  49.     exit 1
  50. }
  51. midifree $in_mfile
  52. midifree $out_mfile
  53. close $in_file
  54. close $out_file
  55. exit 0
  56.